const util = require('../../../utils/util.js');
var user = require('../../../services/user.js');
const Toast = require('../../../utils/toast.js');
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置

Page({
  data: {
    tabs: ["在线课程", "未发布课程", "上线课程"],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,
    linelessonlist:[],
  },
  onLoad: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });
    this.getteacherlesson();
  },
  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });
  },
  getteacherlesson:function(){
    let that = this;
    util.request('school/getteacherlesson', 'GET').then(function (res) {
      console.log(res.data);
      if (res.errno === 0) {
        that.setData({
          linelessonlist: res.data.linelessonlist,
        });
      }
    });
  },
  golessonrecording:function(e){
    let id = e.currentTarget.dataset.id;
    //console.log(id)
    wx.navigateTo({
      url: `../../../pages/recording/recording?id=${id}`
    })
  }
});